﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using BLL;
using BLL.RF.Repair;
using Model.RF.Repair;

/// <summary>
///RepairArea_ChooseRepairPath_CancelRepairRecord_Service 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class RepairArea_ChooseRepairPath_CancelRepairRecord_Service : System.Web.Services.WebService
{
    private Repair repair;
    private RepairRoute rroute;
    private RepairLock rlock;
    private RepairCancel rcancel;

    public RepairArea_ChooseRepairPath_CancelRepairRecord_Service()
    {
        repair = new Repair();
        rroute = new RepairRoute();
        rlock = new RepairLock();
        rcancel = new RepairCancel();
        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod(Description = "根据序列号，先获取有效锁定记录对应工序，进而获取对应工序返修可选路径，返回null时提示无需返修")]
    public List<RepairRouteInfo> RepairRoute_GetbyStepItem(string productSN)
    {
        productSN = CommHelper.GetProductSN(productSN);
        RepairLockInfo rlockinfo = rlock.RepairLock_GetLatestValidbyProductSN(productSN);
        if (!string.IsNullOrEmpty(rlockinfo.StepItem))
        {
            return new List<RepairRouteInfo>(rroute.RepairRoute_GetbyStepItem(rlockinfo.StepItem));
        }
        else
        {
            return null;
        }
    }

    [WebMethod(Description = "维修员选择返修路径，自动生成返修记录")]
    public bool Repair_AutoBuild(string productSN, string repairPath, string userID)
    {
        productSN = CommHelper.GetProductSN(productSN);
        return repair.Repair_AutoBuild(productSN, repairPath, userID);
    }

    [WebMethod(Description = "维修员选择返修路径，自动释放锁定，参数stepItem来自RepairRoute_GetbyStepItem方法")]
    public bool RepairLock_AutoUnlock(string productSN,string stepItem)
    {
        productSN = CommHelper.GetProductSN(productSN);
        RepairLockInfo rli = new RepairLockInfo() { ID = 0, ProductSN = productSN, RecordTime = DateTime.Now, StepItem = stepItem, IsValid = false };
        return rlock.RepairLock_AutoUnlock(rli);
    }

    [WebMethod(Description = "撤消返修记录：解除最近有效锁定记录，或删除最近返修记录")]
    public bool RepairCancel_Add(string productSN, string userID)
    {
        productSN = CommHelper.GetProductSN(productSN);
        return rcancel.RepairCancel_Add(productSN, userID);
    }
}

